<template>
  <div class="app-container">
    <div style="height: 80px" class="tou">
      <h2 style="text-align: center;font-size: 26px">供应商中心</h2>
      <el-button type="primary" icon="el-icon-arrow-left" @click="cancel" style="margin-left: 20px">返回</el-button>
    </div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick" style="padding: 10px 25px 20px">
      <el-tab-pane label="基础资料" name="first" id="first">
        <div class="scrollable-content">
          <el-form ref="form" :model="bs_supplier">
            <div style="padding: 20px 100px">
              <p style="font-size: 18px;text-align: left;border-left: solid 5px;border-color: #0065b5 !important;padding-left: 7px;">审核状态<span style="color: red;">（{{ bs_supplier.fStatus === 0 ? '审核中' : bs_supplier.fStatus === 1 ? '已通过审核' : '已被驳回' }}）</span> </p>
              <el-descriptions class="mine-margin-top" size="medium" :column="2" border>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    供应商名称
                  </template>
                  <el-input type="text" v-model="bs_supplier.hName" disabled placeholder="请输入供应商名称"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    统一社会信用代码
                  </template>
                  <el-input type="text" v-model="bs_supplier.hCreditCode" disabled placeholder="请输入统一社会信用代码"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    单位注册地
                  </template>
                  <el-input type="text" v-model="bs_supplier.hIncorporation" clearable placeholder="请输入单位注册地"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    经营产品
                  </template>
                  <el-input type="text" v-model="bs_supplier.hInstitution" clearable placeholder="请输入经营产品"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    企业性质
                  </template>
                  <el-input type="text" v-model="bs_supplier.hQuality" clearable placeholder="请输入企业性质"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    成立日期
                  </template>
                  <el-date-picker clearable
                                  v-model="bs_supplier.hStartTime"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="请选择成立日期"
                                  style="width: 340px">
                  </el-date-picker>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    法人/负责人
                  </template>
                  <el-input type="text" v-model="bs_supplier.hJuridical" disabled placeholder="请输入法人/负责人姓名"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    法人/负责人身份证号
                  </template>
                  <el-input type="text" v-model="bs_supplier.hJuridicalIdentity" disabled placeholder="请输入身份证号"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    单位联系地址
                  </template>
                  <el-input type="textarea" v-model="bs_supplier.hAddress" placeholder="请输入单位联系地址"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    公司简介
                  </template>
                  <el-input type="textarea" v-model="bs_supplier.hDesc" placeholder="请输入公司简介"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    营业执照有效期
                  </template>
                  <el-date-picker clearable
                                  v-model="bs_supplier.hExpiration"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="请选择营业执照有效期"
                                  style="width: 340px">
                  </el-date-picker>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    经营范围
                  </template>
                  <el-input type="textarea" v-model="bs_supplier.hRange" placeholder="请输入经营范围"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    营业执照扫描件
                  </template>
                  <div class="demo-image__preview">
                    <el-image
                        v-for="(src, index) in hCopiesList"
                        :key="index"
                        style="width: 100px; height: 100px; margin-right: 10px;"
                        :src="src"
                        fit="contain"
                        :preview-src-list="hCopiesList">
                    </el-image>
                  </div>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    法人/负责人身份证扫描件
                  </template>
                  <div class="demo-image__preview">
                    <el-image
                        v-for="(src, index) in idCardCopyList"
                        :key="index"
                        style="width: 100px; height: 100px; margin-right: 10px;"
                        :src="src"
                        fit="contain"
                        :preview-src-list="idCardCopyList">
                    </el-image>
                  </div>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    单位注册地址
                  </template>
                  <el-input type="text" v-model="bs_supplier.hSignAddress" clearable placeholder="请输入单位注册地址"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    单位注册电话
                  </template>
                  <el-input type="text" v-model="bs_supplier.hSignPhone" clearable placeholder="请输入手机号码"/>
                </el-descriptions-item>
              </el-descriptions>
            </div>
            <div style="padding:0 100px;text-align: center">
              <p style="font-size: 18px;text-align: left;border-left: solid 5px;border-color: #0065b5 !important;padding-left: 7px;">开票信息<span style="color: red;font-size: 12px;">（注: 开票信息专用）</span></p>
              <el-descriptions class="mine-margin-top" size="medium" :column="2" border>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    开户行
                  </template>
                  <el-input type="text" v-model="bs_supplier.hBank" clearable placeholder="请输入开户行"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    银行账号
                  </template>
                  <el-input type="text" v-model="bs_supplier.hAccount" clearable placeholder="请输入银行账号"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    开户行地址
                  </template>
                  <el-input type="text" v-model="bs_supplier.hBankAddress" clearable placeholder="请输入开户行地址"/>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                  </template>
                </el-descriptions-item>
                <el-descriptions-item label-style="text-align: center">
                  <template slot="label">
                    注册资本（万元）
                  </template>
                  <el-input v-model="bs_supplier.hCapital" @blur="payHandleBlur(bs_supplier)"
                            @input="payHandleInput(bs_supplier)" clearable placeholder="请输入注册资本"/>
                </el-descriptions-item>
                <el-descriptions-item :span="1" label-style="text-align: center">
                  <template slot="label">
                    实缴资本（万元）
                  </template>
                  <el-input v-model="bs_supplier.hActualCapital" @blur="payHandleBlur1(bs_supplier)"
                            @input="payHandleInput1(bs_supplier)" clearable placeholder="请输入实缴资本"/>
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-form>
          <el-row style="text-align: center;margin-top: 20px">
            <el-button type="primary" @click="yes">确 定</el-button>
            <el-button type="primary" @click="submitCheck" v-if="bs_supplier.fStatus === 2">再次提交审核</el-button>
            <el-tag size="large" style="margin-left: 10px;" type="danger" v-if="bs_supplier.fStatus === 0 || bs_supplier.fStatus === 1">
              {{ bs_supplier.fStatus === 0 ? '审核中' : '已通过审核' }}
            </el-tag>
          </el-row>
        </div>
      </el-tab-pane>
      <el-tab-pane label="我的报名" name="five" id="five">
        <div style="padding: 20px 100px">
          <el-form :model="registration" ref="queryForm5" size="large" :inline="true" label-width="68px" style="margin-bottom: 20px">
            <el-form-item label="招标项目名称" prop="sName" label-width="100px">
              <el-input v-model="registration.sName" placeholder="请输入招标项目名称" clearable @keyup.enter.native="handleQuery5" style="width: 400px"/>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery5" style="margin-left: 30px">搜索</el-button>
              <el-button icon="el-icon-refresh" size="medium" @click="resetQuery5">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table :data="registrationList" style="width: 100%;border-radius: 10px 10px 0 0" stripe v-loading="loading">
            <el-table-column label="序号" align="center" prop="id" />
            <el-table-column label="招标项目编号" align="center" prop="sCode" />
            <el-table-column label="项目名称" align="center" prop="ssName" />
            <el-table-column label="公告名称" align="center" prop="uuTitle" />
            <el-table-column label="供应商" align="center" prop="hhName" />
            <el-table-column label="报名状态" align="center" width="180" prop="currentStatus">
              <template slot-scope="scope">
                <span>{{scope.row.currentStatus === 1?'报名':'已取消'}}</span>
              </template>
            </el-table-column>
            <el-table-column label="报名时间&取消时间" align="center" prop="updateTime" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                    v-if="scope.row.currentStatus === 1"
                    size="mini"
                    type="text"
                    icon="el-icon-delete"
                    @click="handleDeleteRegistration(scope.row)"
                >取消报名</el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination
              v-show="total5>0"
              :total="total5"
              :page.sync="registration.pageNum"
              :limit.sync="registration.pageSize"
              @pagination="listTheRegistration"
              style="text-align: right"
          />
        </div>
      </el-tab-pane>
      <el-tab-pane label="我的投标&竞价" name="fourth">
        <div style="padding: 20px 100px">
          <el-form :model="submission" ref="queryForm3" size="large" :inline="true"
                   label-width="68px" style="margin-bottom: 20px">
            <el-form-item label="招标项目名称" prop="sName" label-width="100px">
              <el-input
                  v-model="submission.sName"
                  placeholder="请输入招标项目名称"
                  clearable
                  @keyup.enter.native="handleQuery3"
                  style="width: 400px"
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery3"
                         style="margin-left: 30px">搜索
              </el-button>
              <el-button icon="el-icon-refresh" size="medium" @click="resetQuery3">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table :data="submissions" style="width: 100%;border-radius: 10px 10px 0 0" stripe v-loading="loading">
            <el-table-column type="index" label="序号" width="60px"></el-table-column>
            <el-table-column property="sCode" label="招标项目编号"></el-table-column>
            <el-table-column property="sName" label="招标项目名称"></el-table-column>
            <el-table-column label="招标方式" width="80px;">
              <template slot-scope="scope">
                <span v-if="scope.row.sWay === 1">公开招标</span>
                <span v-if="scope.row.sWay === 2">邀请招标</span>
              </template>
            </el-table-column>
            <el-table-column property="createTime" label="投标开始时间" width="115px;"></el-table-column>
            <el-table-column property="uEndTime" label="投标截止时间" width="115px;"></el-table-column>
            <el-table-column property="tdSuccessTime" label="成功递交时间" width="115px;"></el-table-column>
            <el-table-column label="投标状态" width="80px;">
              <template slot-scope="scope">
                <el-tag type="success" v-if="scope.row.tdStatus === 0">成功</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="上传附件" width="400px;">
              <template slot-scope="scope">
                <p v-for="i in JSON.parse(scope.row.fjFiles)" v-if="scope.row.fjFiles != null">
                  <a :href="i.url" target="_blank">{{ i.name }}</a>
                </p>
                <p v-if="scope.row.fjFiles == null" style="color: #0065B5">---</p>
              </template>
            </el-table-column>
            <el-table-column label="初始报价" width="90px;">
              <template slot-scope="scope">
                <span>{{formatNumberWithCommas(scope.row.startPrice)}}&nbsp;元</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="250px;">
              <template slot-scope="scope">
                <el-button type="text" v-if="scope.row.fjFiles != null" @click="download(JSON.parse(scope.row.fjFiles))">
                  下载附件<i class="el-icon-download"></i>
                </el-button>
                <p v-if="scope.row.fjFiles == null" style="color: #0065B5">---</p>
                <el-button type="text" @click="modifyBidding(scope.row)">修改投标</el-button>
                <el-button type="text" @click="viewNotice(scope.row)">招标公告</el-button>
                <el-button type="text" @click="viewTender(scope.row)">招标详情</el-button>
                <el-button type="text" @click="viewPlan(scope.row)">采购详情</el-button>
                <el-button type="danger" @click="goBidding(scope.row)">去竞价</el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination
              v-show="total4>0"
              :total="total4"
              :page.sync="submission.pageNum"
              :limit.sync="submission.pageSize"
              @pagination="listSubmission"
              style="text-align: right"
          />
        </div>
      </el-tab-pane>
      <el-tab-pane label="非招标项目&报价" name="third">
        <div style="padding: 20px 100px">
          <el-tabs v-model="activeName1" type="card" tab-position="left" @tab-click="handleClick1">
            <el-tab-pane label="可参与项目" name="one">
              <el-form :model="nobid" ref="queryForm1" size="large" :inline="true"
                       label-width="68px" style="margin-bottom: 20px">
                <el-form-item label="采购项目名称" prop="gName" label-width="100px">
                  <el-input
                      v-model="nobid.gName"
                      placeholder="请输入采购项目名称"
                      clearable
                      @keyup.enter.native="handleQuery1"
                      style="width: 400px"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery1"
                             style="margin-left: 30px">搜索
                  </el-button>
                  <el-button icon="el-icon-refresh" size="medium" @click="resetQuery1">重置</el-button>
                </el-form-item>
              </el-form>
              <el-table
                  :data="nobids"
                  style="width: 100%;border-radius: 10px 10px 0 0"
                  stripe
                  v-loading="loading">
                <el-table-column
                    type="index"
                    label="序号"
                    width="120px">
                </el-table-column>
                <el-table-column
                    property="gCode"
                    label="采购项目编号">
                </el-table-column>
                <el-table-column
                    property="gName"
                    label="采购项目名称">
                </el-table-column>
                <el-table-column
                    property="gTimeon"
                    label="开始时间">
                </el-table-column>
                <el-table-column
                    property="gDeadline"
                    label="报价截止时间">
                </el-table-column>
                <el-table-column
                    label="操作">
                  <template slot-scope="scope">
                    <el-button type="primary" @click="join(scope.row)">参与项目</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <pagination
                  v-show="total2>0"
                  :total="total2"
                  :page.sync="nobid.pageNum"
                  :limit.sync="nobid.pageSize"
                  @pagination="listNoBid"
                  style="text-align: right"
              />
            </el-tab-pane>
            <el-tab-pane label="正参与项目" name="two">
              <el-form :model="nobidSupNon" ref="queryForm2" size="large" :inline="true"
                       label-width="68px" style="margin-bottom: 20px">
                <el-form-item label="采购项目名称" prop="gfName" label-width="100px">
                  <el-input
                      v-model="nobidSupNon.gfName"
                      placeholder="请输入采购项目名称"
                      clearable
                      @keyup.enter.native="handleQuery2"
                      style="width: 400px"
                  />
                </el-form-item>
                <el-form-item label="报价状态" prop="gfQstate" label-width="110px">
                  <el-select v-model="nobidSupNon.gfQstate" placeholder="请选择报价状态"
                             @keyup.enter.native="handleQuery2" style="width: 400px">
                    <el-option value="0" label="未报价">
                      未报价
                    </el-option>
                    <el-option value="1" label="已报价">
                      已报价
                    </el-option>
                    <el-option value="2" label="撤销报价">
                      撤销报价
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery2"
                             style="margin-left: 30px">搜索
                  </el-button>
                  <el-button icon="el-icon-refresh" size="medium" @click="resetQuery2">重置</el-button>
                </el-form-item>
              </el-form>
              <el-table
                  :data="nobidSupNons"
                  style="width: 100%;border-radius: 10px 10px 0 0"
                  stripe
                  v-loading="loading">
                <el-table-column
                    type="index"
                    label="序号"
                    width="120px">
                </el-table-column>
                <el-table-column
                    property="gfId"
                    label="采购项目编号">
                </el-table-column>
                <el-table-column
                    property="gfName"
                    label="采购项目名称">
                </el-table-column>
                <el-table-column
                    property="gfQtime"
                    label="报价截止时间">
                </el-table-column>
                <el-table-column
                    label="报价状态">
                  <template slot-scope="scope">
                    <el-tag v-if="scope.row.gfQstate === 0">未报价</el-tag>
                    <el-tag type="success" v-if="scope.row.gfQstate === 1">已报价</el-tag>
                    <el-tag type="info" v-if="scope.row.gfQstate === 2">撤销报价</el-tag>
                  </template>
                </el-table-column>
                <el-table-column
                    label="操作">
                  <template slot-scope="scope">
                    <router-link :to="'/quotation?gfId='+scope.row.gfId+'&state='+scope.row.gfQstate">
                      <el-button type="primary" v-if="scope.row.gfQstate === 0 || scope.row.gfQstate === 2">
                        报价
                      </el-button>
                    </router-link>
                    <el-button type="primary" @click="che(scope.row)" v-if="scope.row.gfQstate === 1">
                      报价撤销
                    </el-button>
                    <router-link :to="'/quotation?gfId='+scope.row.gfId+'&state='+scope.row.gfQstate">
                      <el-button type="primary" v-if="scope.row.gfQstate === 1" style="margin-left: 10px">
                        查看报价
                      </el-button>
                    </router-link>
                  </template>
                </el-table-column>
              </el-table>
              <pagination
                  v-show="total3>0"
                  :total="total3"
                  :page.sync="nobidSupNon.pageNum"
                  :limit.sync="nobidSupNon.pageSize"
                  @pagination="listNoSupNonBid"
                  style="text-align: right"
              />
            </el-tab-pane>
          </el-tabs>
        </div>
      </el-tab-pane>
      <el-tab-pane label="我的合同" name="second">
        <div style="padding: 20px 100px">
          <el-form :model="contract" ref="queryForm" size="large" :inline="true"
                   label-width="68px" style="margin-bottom: 20px">
            <el-form-item label="合同名称" prop="eHname">
              <el-input
                  v-model="contract.eHname"
                  placeholder="请输入合同名称"
                  clearable
                  @keyup.enter.native="handleQuery"
                  style="width: 400px"
              />
            </el-form-item>
            <el-form-item label="状态" prop="oHstatus" label-width="110px">
              <el-select v-model="contract.oHstatus" placeholder="请选择状态"
                         @keyup.enter.native="handleQuery" style="width: 400px">
                <el-option value="1" label="待供方确认">
                  待供方确认
                </el-option>
                <el-option value="2" label="待签订">
                  待签订
                </el-option>
                <el-option value="3" label="生效合同">
                  生效合同
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery"
                         style="margin-left: 30px">搜索
              </el-button>
              <el-button icon="el-icon-refresh" size="medium" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table
              :data="contracts"
              style="width: 100%;border-radius: 10px 10px 0 0"
              stripe
              v-loading="loading">
            <el-table-column
                type="index"
                label="序号">
            </el-table-column>
            <el-table-column
                property="eHcode"
                label="合同编号">
            </el-table-column>
            <el-table-column
                property="eHname"
                label="合同名称">
            </el-table-column>
            <el-table-column
                property="bsSupplier.hName"
                label="供应商">
            </el-table-column>
            <el-table-column
                property="createBy"
                label="申请人">
            </el-table-column>
            <el-table-column
                property="createTime"
                label="创建日期">
            </el-table-column>
            <el-table-column
                property="eDeliveryTime"
                label="交付日期">
            </el-table-column>
            <el-table-column
                property="eAmount"
                label="合同金额">
              <template slot-scope="scope">
                {{ scope.row.eAmount.toFixed(2) }}元
              </template>
            </el-table-column>
            <el-table-column
                property="eType"
                label="合同类型">
            </el-table-column>
            <el-table-column
                property="eStartdate"
                label="合同生效日期">
            </el-table-column>
            <el-table-column
                property="eEnddate"
                label="合同结束日期">
            </el-table-column>
            <el-table-column
                property="oHstatus"
                label="状态">
              <template slot-scope="scope">
                <el-tag class="mine-el-tag" size="small" v-if="scope.row.oHstatus == 1" type="danger">待供方确认
                </el-tag>
                <el-tag class="mine-el-tag" size="small" v-if="scope.row.oHstatus == 2" type="primary">待签订
                </el-tag>
                <el-tag class="mine-el-tag" size="small" v-if="scope.row.oHstatus == 3 && scope.row.eCancel == 0" type="success">生效合同
                </el-tag>
                <el-tag class="mine-el-tag" size="small" v-if="scope.row.oHstatus == 3 && scope.row.eCancel == 1" type="info">作废合同
                </el-tag>
              </template>
            </el-table-column>
          </el-table>
          <pagination
              v-show="total1>0"
              :total="total1"
              :page.sync="contract.pageNum"
              :limit.sync="contract.pageSize"
              @pagination="myContract"
              style="text-align: right"
          />
        </div>
      </el-tab-pane>
    </el-tabs>

    <el-dialog title="修改报价文件" :visible.sync="centerDialogVisible" width="30%" center>
      <span>
          <el-form>
            <el-form-item label="起始报价：" prop="startPrice">
              <span>(注意：竞标时，该值将用作供应商提供的“初次报价”来竞标)</span>
              <el-input v-model="startPrice" placeholder="请输入起始报价" clearable :style="{width: '45%'}"></el-input><span style="color: red;">（注：含增值税，单位：{{ currencyUnit }}，币别：{{ currencyCategory }}）</span>
            </el-form-item>
            <el-form-item label="附件：" prop="fjAnnex">
                      <el-upload ref="upload" class="upload-demo" :limit="5" accept=".doc, .docx, .pdf, .xls, .xlsx, .rar, .txt, .png, .jpg, .zip"
                                 :max-size="104857600"
                                 :action="upload.url"
                                 :on-change="changeFileLength"
                                 :headers="upload.headers" :file-list="upload.fileList" :before-remove="beforeRemove"
                                 :multiple="true"
                                 :on-progress="handleFileUploadProgress"
                                 :before-upload="beforeUpload"
                                 :on-success="handleFileSuccess" :auto-upload="false">
                        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                        <div slot="tip" class="el-upload__tip" style="font-size: 14px;">只能上传.doc，.docx，.pdf，.xls，.xlsx，.rar，.txt，.png，.jpg文件，可以多选</div>
                      </el-upload>
            </el-form-item>
          </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitUpload">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

import {getNobid, getSupplier, listNoBid, listSubmission, updateSupplier} from "@/api/system/supplier";
import {listContract} from "@/api/system/cm";
import Pagination from "@/components/Pagination/index.vue";
import {addPro, check, listPro, updatePro} from "@/api/system/nobidSupNonPro";
import {oneQuo, updateQuotation} from "@/api/system/quotation";
import modal from "@/plugins/modal";
import {delRegistration, findBiddingRule, listRegistration} from "@/api/system/tender";
import {findTwoInfo} from "@/api/home";
import {getToken} from "@/utils/auth";
import {addSubmission, getSubmission, getSubmissionByHidAndSid, updateSubmission} from "@/api/submission";

export default {
  name: "mine",
  components: {Pagination},
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: 'first',
      activeName1: 'one',
      contracts: [],
      nobids: [],
      nobidSupNons: [],
      submissions: [],
      registrationList:[],
      total1: 0,
      total2: 0,
      total3: 0,
      total4: 0,
      total5: 0,
      submission: {
        hid: JSON.parse(sessionStorage.getItem('bsSupplier')).hid,
        sName: null,
        pageNum: 1,
        pageSize: 10
      },
      biddingSubmission:{
        sid:null,
        hid:null,
        fjFiles:null,
        startPrice:null,
        currencyUnit:null,
        currencyCategory:null,
      },
      registration:{
        hid: JSON.parse(sessionStorage.getItem('bsSupplier')).hid,
        pageNum: 1,
        pageSize: 10
      },
      nobid: {
        gName: null,
        pageNum: 1,
        pageSize: 10
      },
      nobidSupNon: {
        hid: JSON.parse(sessionStorage.getItem('bsSupplier')).hid,
        gfName: null,
        gfQstate: null,
        pageNum: 1,
        pageSize: 10
      },
      contract: {
        hid: JSON.parse(sessionStorage.getItem('bsSupplier')).hid,
        pageNum: 1,
        pageSize: 10,
        eHname: null,
        oHstatus: null
      },
      bs_supplier: {
        hid: JSON.parse(sessionStorage.getItem('bsSupplier')).hid,
        hName: null,
        hCreditCode: null,
        hIncorporation: null,
        hInstitution: null,
        hQuality: null,
        hStartTime: null,
        hJuridical: null,
        hJuridicalIdentity: null,
        hAddress: null,
        hRange: null,
        hDesc: null,
        hJuridicalCopies: null,
        hExpiration: null,
        hBank: null,
        hAccount: null,
        hBankAddress: null,
        hSignPhone: '',
        hSignAddress: '',
        hCapital: null,
        hActualCapital: null,
        hProve: null,
        fState: null,
        fStatus: null
      },
      //营业执照
      hCopies: '',
      hCopiesList: [],
      //法人身份证
      idCardCopy: '',
      idCardCopyList: [],
      centerDialogVisible: false,
      startPrice: null,
      currencyUnit: '',
      currencyCategory: '',
      //附件
      fileList:[],
      // 收集——上传文件的列表
      uploadFiles: [],
      // 收集——上传文件的个数
      filesLength: 0,
      //收集已上传的文件名
      fileNameList:[],
      urls:[],
      fjList:[],
      //未上传前文件列表
      noFiles:[],
      //未上传清除后文件列表
      noFiles2:[],
      // 上传参数
      upload: {
        // 上传的文件列表
        fileList: [],
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken()
        },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/bidding/documents/upload1",
      }
    }
  },
  created() {
    if (sessionStorage.getItem('token') == null) {
      this.$router.push('/')
    }
    if (sessionStorage.getItem('m1') != null) {
      //标签页
      this.activeName = sessionStorage.getItem('m1')
      sessionStorage.removeItem('m1')

      if (sessionStorage.getItem('n1') != null && sessionStorage.getItem('s1') != null) {
        this.contract.pageNum = JSON.parse(sessionStorage.getItem('n1'))
        this.contract.pageSize = JSON.parse(sessionStorage.getItem('s1'))

        sessionStorage.removeItem('n1')
        sessionStorage.removeItem('s1')
      }
      if (sessionStorage.getItem('m2') != null && sessionStorage.getItem('n2') != null && sessionStorage.getItem('s2') != null) {
        this.nobid.pageNum = JSON.parse(sessionStorage.getItem('n2'))
        this.nobid.pageSize = JSON.parse(sessionStorage.getItem('s2'))
        this.activeName1 = sessionStorage.getItem('m2')

        sessionStorage.removeItem('n2')
        sessionStorage.removeItem('s2')
        sessionStorage.removeItem('m2')
      }
      if (sessionStorage.getItem('m3') != null && sessionStorage.getItem('n3') != null && sessionStorage.getItem('s3') != null) {
        this.nobidSupNon.pageNum = JSON.parse(sessionStorage.getItem('n3'))
        this.nobidSupNon.pageSize = JSON.parse(sessionStorage.getItem('s3'))
        this.activeName1 = sessionStorage.getItem('m3')

        sessionStorage.removeItem('n3')
        sessionStorage.removeItem('s3')
        sessionStorage.removeItem('m3')
      }
      if (sessionStorage.getItem('n4') != null && sessionStorage.getItem('s4') != null) {
        this.submission.pageNum = JSON.parse(sessionStorage.getItem('n4'))
        this.submission.pageSize = JSON.parse(sessionStorage.getItem('s4'))

        sessionStorage.removeItem('n4')
        sessionStorage.removeItem('s4')
      }
    }
    this.query();
    this.myContract();
    this.listNoBid();
    this.listNoSupNonBid();
    this.listSubmission();
    this.listTheRegistration();
  },
  beforeRouteLeave(to, from, next) {
    sessionStorage.setItem('m1', this.activeName)
    if (this.activeName === 'second') {
      //  合同
      sessionStorage.setItem('n1', this.contract.pageNum)
      sessionStorage.setItem('s1', this.contract.pageSize)
    } else if (this.activeName === 'third' && this.activeName1 === 'one') {
      //  报价
      sessionStorage.setItem('m2', this.activeName1)
      sessionStorage.setItem('n2', this.nobid.pageNum)
      sessionStorage.setItem('s2', this.nobid.pageSize)
    } else if (this.activeName === 'third' && this.activeName1 === 'two') {
      //  报价
      sessionStorage.setItem('m3', this.activeName1)
      sessionStorage.setItem('n3', this.nobidSupNon.pageNum)
      sessionStorage.setItem('s3', this.nobidSupNon.pageSize)
    } else if (this.activeName === 'fourth') {
      //  投标
      sessionStorage.setItem('n4', this.submission.pageNum)
      sessionStorage.setItem('s4', this.submission.pageSize)
    }
    next(true)
  },
  methods: {
    download(fileUrls) {
      if (fileUrls.length === 0) {
        this.$message.error("没有附件可下载，请上传附件！！")
        return;
      }
      let files = fileUrls.map(function (obj) {
        return obj.url
      })
      let urls = files.join(',')
      let name = encodeURIComponent(urls);
      let url = process.env.VUE_APP_BASE_API + `/basic/supplier/downloadZip?url=${name}`;
      const a = document.createElement('a')
      a.setAttribute('target', '_blank')
      a.setAttribute('href', url)
      a.click()
    },
    handleClick(tab, event) {
      console.log(tab, event)
    },
    handleClick1(tab, event) {
      console.log(tab, event)
    },
    cancel() {
      this.$router.back()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.contract.pageNum = 1;
      this.myContract();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$refs.queryForm.resetFields()
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery1() {
      this.nobid.pageNum = 1;
      this.listNoBid();
    },
    /** 重置按钮操作 */
    resetQuery1() {
      this.$refs.queryForm1.resetFields()
      this.handleQuery1();
    },
    /** 搜索按钮操作 */
    handleQuery2() {
      this.nobidSupNon.pageNum = 1;
      this.listNoSupNonBid();
    },
    /** 重置按钮操作 */
    resetQuery2() {
      this.$refs.queryForm2.resetFields()
      this.handleQuery2();
    },
    /** 搜索按钮操作 */
    handleQuery3() {
      this.submission.pageNum = 1;
      this.listSubmission();
    },
    /** 重置按钮操作 */
    resetQuery3() {
      this.$refs.queryForm3.resetFields()
      this.handleQuery3();
    },
    listSubmission() {
      this.loading = true;
      listSubmission(this.submission).then(res => {
        console.log(res)
        this.submissions = res.data.rows;
        this.total4 = res.data.total;
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery5() {
      this.registration.pageNum = 1;
      this.listTheRegistration();
    },
    /** 重置按钮操作 */
    resetQuery5() {
      this.$refs.queryForm5.resetFields()
      this.handleQuery5();
    },
    listTheRegistration() {
      this.loading = true;
      listRegistration(this.registration).then(res => {
        this.registrationList = res.data.rows;
        this.total5 = res.data.total;
        this.loading = false;
      })
    },
    /** 删除按钮操作 */
    handleDeleteRegistration(row) {
      const ids = row.id || this.ids;
      const uid = row.uid;
      findTwoInfo(uid).then(res => {
        if(res.data.data){
          const endTime = res.data.data.uEndTime + '';
          const now = new Date().getTime();
          const otherDate = new Date(endTime).getTime();
          if(now > otherDate){
            modal.alertError("已过投标截止时间，不能取消！");
            return;
          }
        }

        this.$confirm('是否确认取消编号为"' + ids + '"的竞标报名？', '消息', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delRegistration(ids).then(res => {
            if(res.data && res.data.code === 200){
              this.listTheRegistration();
              this.$message.success("撤销成功")
            }else{
              this.$message.error("撤销失败")
            }
          });
        }).catch(() => {
          return false
        });
      });
    },
    listNoSupNonBid() {
      this.loading = true;
      listPro(this.nobidSupNon).then(res => {
        this.nobidSupNons = res.data.rows;
        this.total3 = res.data.total;
        this.loading = false;
      })
    },
    listNoBid() {
      this.loading = true;
      listNoBid(this.nobid).then(res => {
        this.nobids = res.data.rows;
        this.total2 = res.data.total;
        this.loading = false;
      })
    },
    myContract() {
      this.loading = true;
      listContract(this.contract).then(res => {
        console.log(res)
        this.contracts = res.data.rows;
        this.total1 = res.data.total;
        this.loading = false;
      })
    },
    goBidding(row){
      if (sessionStorage.getItem("token") == null) {
        modal.alertWarning("注册供应商并登录后竞价")
      } else {
        //window.open('#/goBidding?uid='+ row.uid+'&sid='+ row.sid + '&xyId=' + row.xyId +'&type=bidNotice&read=1', '_blank');
        this.$router.push('/goBidding?uid='+ row.uid+'&sid='+ row.sid + '&xyId=' + row.xyId +'&type=bidNotice&read=1');
      }
    },
    modifyBidding(row){
      //查询看有没有竞标规则
      findBiddingRule(row.sid,this.bs_supplier.hid).then(response=>{
        if(response.data && response.data.data){
          const bidPriceRule = response.data.data;
          this.currencyCategory = bidPriceRule.currencyCategory;
          this.currencyUnit = bidPriceRule.currencyUnit;
        }else{
          this.currencyCategory = 'RMB';
          this.currencyUnit = '元';
        }

        getSubmissionByHidAndSid(this.bs_supplier.hid,row.sid).then(res=>{
          if(res.data && res.data.code === 200 && res.data.data){
            this.biddingSubmission.startPrice = res.data.data.startPrice;
            this.biddingSubmission.currencyUnit = res.data.data.currencyUnit;
            this.biddingSubmission.currencyCategory = res.data.data.currencyCategory;
            this.biddingSubmission.sid = row.sid;//设置值，当提交的时候使用，提交成功后又会清空该值
            this.startPrice = res.data.data.startPrice;
            this.currencyUnit = res.data.data.currencyUnit;
            this.currencyCategory = res.data.data.currencyCategory;
            if(res.data.data.fjFiles){
              this.upload.fileList= JSON.parse(res.data.data.fjFiles);
            }
            this.centerDialogVisible = true;
          }else{
            this.$message.error("修改失败，投标报价信息不存在！")
          }
        });
      });
    },
    viewNotice(row){
      this.$router.push('/detail?uid='+ row.uid+'&sid='+ row.sid+'&type=bidNotice&read=1');
    },
    viewTender(row){
      this.$router.push('/tender/details?type=details&sid='+row.sid);
    },
    viewPlan(row){
      this.$router.push('/planDetail?aid='+row.xyId);
    },
    join(param) {
      check({"hid": this.bs_supplier.hid, "gf_id": param.gCode}).then(res => {
        console.log(res)
        if (res.data.msg === 'yes') {
          //可以参加
          addPro({
            "gfId": param.gCode,
            "hid": this.bs_supplier.hid,
            "gfName": param.gName,
            "gfQtime": param.gDeadline,
            "gfQstate": 0
          }).then(response => {
            if (response.data.code === 200) {
              this.$message.success("参加成功！")
              this.listNoSupNonBid()
            }
          })
        } else {
          this.$message.info("您正在参加该项目哦")
        }
      })
    },
    /** 基础资料 */
    query() {
      getSupplier(this.bs_supplier.hid).then(response => {
        console.log(response)
        this.bs_supplier.hName = response.data.data.hName
        this.bs_supplier.hCreditCode = response.data.data.hCreditCode
        this.bs_supplier.hIncorporation = response.data.data.hIncorporation
        this.bs_supplier.hInstitution = response.data.data.hInstitution
        this.bs_supplier.hQuality = response.data.data.hQuality
        this.bs_supplier.hStartTime = response.data.data.hStartTime
        this.bs_supplier.hJuridical = response.data.data.hJuridical
        this.bs_supplier.hJuridicalIdentity = response.data.data.hJuridicalIdentity
        this.bs_supplier.hAddress = response.data.data.hAddress
        this.bs_supplier.hRange = response.data.data.hRange
        this.bs_supplier.hDesc = response.data.data.hDesc
        this.bs_supplier.hExpiration = response.data.data.hExpiration
        this.bs_supplier.hBank = response.data.data.hBank
        this.bs_supplier.hBankAddress = response.data.data.hBankAddress
        this.bs_supplier.hSignPhone = response.data.data.hSignPhone
        this.bs_supplier.hSignAddress = response.data.data.hSignAddress
        this.bs_supplier.hCapital = response.data.data.hCapital
        this.bs_supplier.hActualCapital = response.data.data.hActualCapital
        this.bs_supplier.fState = response.data.data.fState
        this.bs_supplier.hAccount = response.data.data.hAccount
        this.bs_supplier.fStatus = response.data.data.fStatus
        this.hCopies = JSON.parse(response.data.data.hCopies)[0].url
        this.hCopiesList.push(JSON.parse(response.data.data.hCopies)[0].url)
        this.idCardCopy = JSON.parse(response.data.data.hJuridicalCopies)[0].url
        for (let i = 0; i < JSON.parse(response.data.data.hJuridicalCopies).length; i++) {
          this.idCardCopyList.push(JSON.parse(response.data.data.hJuridicalCopies)[i].url)
        }
      });
    },
    payHandleBlur(row) {
      if (row.hCapital) {
        row.hCapital = parseFloat(row.hCapital).toFixed(0)
      }
    },
    payHandleInput(row) {
      // 只保留数字和一个小数点
      row.hCapital = row.hCapital.replace(/[^\d]/g, '')
      // 只能输入一个小数点
      let dotIndex = row.hCapital.indexOf('.')
      if (dotIndex !== -1) {
        row.hCapital = row.hCapital.slice(0, dotIndex + 1) + row.hCapital.slice(dotIndex + 1).replace(/\./g, '')
      }
      // 只能输入到小数点后两位
      let parts = row.hCapital.split('.')
      if (parts[1] && parts[1].length > 2) {
        row.hCapital = parts[0] + '.' + parts[1].slice(0, 2)
      }
    },
    payHandleBlur1(row) {
      if (row.hActualCapital) {
        row.hActualCapital = parseFloat(row.hActualCapital).toFixed(0)
      }
    },
    payHandleInput1(row) {
      // 只保留数字和一个小数点
      row.hActualCapital = row.hActualCapital.replace(/[^\d]/g, '')
      // 只能输入一个小数点
      let dotIndex = row.hActualCapital.indexOf('.')
      if (dotIndex !== -1) {
        row.hActualCapital = row.hActualCapital.slice(0, dotIndex + 1) + row.hActualCapital.slice(dotIndex + 1).replace(/\./g, '')
      }
      // 只能输入到小数点后两位
      let parts = row.hActualCapital.split('.')
      if (parts[1] && parts[1].length > 2) {
        row.hActualCapital = parts[0] + '.' + parts[1].slice(0, 2)
      }
    },
    submitCheck() {
      this.bs_supplier.fStatus = 0;//关键的一句
      updateSupplier(this.bs_supplier).then(res => {
        if (res.data.code === 200) {
          this.$message.success(res.data.msg)
        }else{
          this.bs_supplier.fStatus = 2;//关键的一句
        }
        this.query()
      })
    },
    yes() {
      updateSupplier(this.bs_supplier).then(res => {
        if (res.data.code === 200) {
          this.$message.success(res.data.msg)
        }
        this.query()
      })
    },
    che(row) {
      this.$confirm("是否撤销该报价?", '消息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        getNobid({"code": row.gfId}).then(res => {
          console.log(res)
          let gRelease = res.data.data.gRelease
          if(gRelease === 2){
            this.$message.info("项目已完成，不能撤销")
            return;
          }
          updateQuotation({"gfId": row.gfId, "bjHid": row.hid, "isDelete": 1}).then(res => {
            if (res.data.code === 200) {
              updatePro({"gfId": row.gfId, "hid": row.hid, "gfQstate": 2}).then(response => {
                if (response.data.code === 200) {
                  this.$message.success("撤销成功")
                  this.listNoSupNonBid()
                }
              })
            }
          })
        })
      }).catch(() => {
        return false
      });
    },
    // 文件提交处理
    submitUpload() {
      if(!this.isInputDigits(this.startPrice)){
        this.$message.warning('请输入起始报价！');
        return;
      }
      if(!this.isAllDigits(this.startPrice)){
        this.$message.warning('请输入正确的起始报价！');
        return;
      }
      //上传标书以及后续操作
      this.$refs.upload.submit();
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 修改当前文件列表长度
    changeFileLength(file, fileList){
      this.noFiles.push(file);
      this.filesLength = fileList.length;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      const url =response.data.data.url;
      this.urls.push({id: this.urls.length + 1, url});
      this.fjList.push({id: this.fjList.length + 1, ...file });
      this.uploadFiles.push(file);
      //每上传完一个文件都会执行该函数，所以必须等上传完成后再提交表单
      if (this.uploadFiles.length === this.filesLength){
        //清空未上传文件列表
        this.noFiles2=[];
        let fjLists = this.fjList.map(obj=>{
          let newObj = obj;
          delete newObj.percentage;
          delete newObj.raw;
          delete newObj.status;
          delete newObj.response;
          obj.url = '';
          return newObj;
        });
        const result = fjLists.map((item, index) => {
          item.url = this.urls[index].url;
          return item;
        });
        this.biddingSubmission.fjFiles = JSON.stringify(result);//投标书
        this.biddingSubmission.startPrice = this.startPrice;
        this.biddingSubmission.currencyUnit = this.currencyUnit;
        this.biddingSubmission.currencyCategory = this.currencyCategory;
        this.biddingSubmission.hid = this.bs_supplier.hid;
        //添加投递标书供应商
        if(this.biddingSubmission.sid != null && this.biddingSubmission.fjFiles!=null){
          updateSubmission(this.biddingSubmission).then(res=>{
            if(res.data && res.data.code === 200){
              this.biddingSubmission.fjFiles = null;//投标书清空
              this.biddingSubmission.hid = null;//投标书清空
              this.biddingSubmission.startPrice = null;
              this.biddingSubmission.currencyUnit = null;
              this.biddingSubmission.currencyCategory = null;
              this.biddingSubmission.sid = null;//招标项目id清空
              this.upload.fileList = [];
              this.uploadFiles = [];
              this.startPrice = null;
              this.currencyUnit = null;
              this.currencyCategory = null;
              modal.msgSuccess("修改成功！");
            }else{
              this.$message.error("修改失败，请核实投标截止时间！")
            }
          });
        }
      }
      this.centerDialogVisible = false;
      this.upload.isUploading = false;
    },
    beforeRemove(file, fileList) {
      this.noFiles2 =  this.noFiles.filter(f=>f.name !== file.name);
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    beforeUpload(file) {
      const isLt5M = file.size / 1024 / 1024 < 100;
      if (!isLt5M) {
        this.$message.error('文件大小不能超过100MB');
      }
      return isLt5M;
    },
    isInputDigits(input) {
      // 处理null、undefined和非字符串输入
      if (input === null || input === undefined) {
        return false;
      }
      // 转换为字符串处理
      const str = String(input);
      // 空字符串不算全数字
      if (str.length === 0) {
        return false;
      }
      return true;
    },
    isAllDigits(input) {
      // 处理null、undefined和非字符串输入
      if (input === null || input === undefined) {
        return false;
      }
      // 转换为字符串处理
      const str = String(input);
      // 空字符串不算全数字
      if (str.length === 0) {
        return false;
      }
      // 使用正则表达式检查是否全部为数字
      return /^\d+$/.test(str);
    },
    formatNumberWithCommas(number) {
      return new Intl.NumberFormat('en-US').format(number);
    }
  }
}
</script>
<style>
* {
  margin: 0;
  padding: 0;
}

/* 隐藏滚动条 */
/*html, body {
  overflow-y: hidden; !* 注意这可能会导致用户体验问题 *!
}*/

.mine-el-tag{
  padding-left: 10px;
  padding-right: 10px;
}

.el-input__inner {
  border: 1px solid #DCDFE6;
}

.el-textarea__inner {
  border: 1px solid #DCDFE6;
}

.el-date-editor.el-input, .el-date-editor.el-input__inner {
  width: 100%;
}

.tou {
  background: url('/public/images/bj.2c9500fa.png') 50%;
  background-size: 1920px 188px;
}

.app-container {
  background-color: #FFFFFF;
}


.mine-margin-top .el-descriptions--medium.is-bordered .el-descriptions-item__cell {
  padding: 7px 15px;
}


</style>
